package com.trustasia.action;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.trustasia.model.UserModel;

@Controller
public class RegisterController<f> {
	@RequestMapping(value = "/reg/regform", method = RequestMethod.GET)
	public String showForm() {
		return "reg";
	}

	@RequestMapping(value = "/reg/regform", method = RequestMethod.POST)
	public String submitForm(@Valid @ModelAttribute("user") UserModel user,
			Errors errors) {
		if (errors.hasErrors()) {
			for (FieldError e : errors.getFieldErrors()) {
				System.out.println("----" + e.getObjectName());
				System.out.println("----" + e.getDefaultMessage());
			}
			return "reg";
		}
		return "index";
	}
}
